package com.nopcomm.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.nopcomm.abstractTest;

public class Categorypage extends abstractTest {
	public void createNewCategory(String categoryname,String path,String parentcategory,String pricerange) {
		// click on Add new
		driver.findElement(By.linkText("Add new")).click();
		//Category Name
		driver.findElement(By.id("Name")).sendKeys(categoryname);
		//upload picture 
		 driver.findElement(By.name("file")).sendKeys(path);
		 //select parent category
	  WebElement element = driver.findElement(By.id("ParentCategoryId-input"));
	  element.clear();
	  element.sendKeys(parentcategory);
		 //Price ranges
		 driver.findElement(By.id("PriceRanges")).sendKeys(pricerange);
		 //show on Homepage
		 driver.findElement(By.id("ShowOnHomePage")).click();
		 //click to save
		 driver.findElement(By.name("save")).click();
		
		
	
	}

	public boolean isCategorymesgshown() {
		// 
		return driver.getPageSource().contains("The new category has been added successfully.");
	}

	public void searchcategory(String categoryname) {
		//category name in search 
		driver.findElement(By.id("SearchCategoryName")).sendKeys(categoryname);
		//click search
		driver.findElement(By.id("btnSearch")).click();
		
		
	}

	public boolean getcategory(String categoryname){
		try {
			Thread.sleep(3000);} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();	}
		return driver.getPageSource().contains(categoryname);	}
	public void deletecategory(String categoryname){
		// delete category
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(driver.getPageSource().contains(categoryname)){
		driver.findElement(By.xpath("(//a[contains(text(),'Edit')])")).click();}
		//Click Delete
		driver.findElement(By.id("category-delete")).click();
		//confirm delete
		driver.findElement(By.xpath("//input[@value='Delete']")).click();
	
	
		
	}

	public boolean isDeletemeshshown() {
		//                                 
		return driver.getPageSource().contains("The category has been deleted successfully.");
	}
	

}
